import { createSlice } from "@reduxjs/toolkit";
import { login2 } from "../../apis/login";

const userSlice = createSlice({
  name: "user",
  initialState: {
    username:'',
    password:'',
    accessToken:''
  },
  reducers: {
    userAdd(state, action) {
      state.username=action.payload.username
      state.password=action.payload.password
      state.accessToken=action.payload.accessToken
    },
  },
});
export const login=(loginForm)=>{
    return async (dispatch)=>{


        const res=await login2(loginForm)
        console.log(res)
        dispatch(userAdd({username:loginForm.username,password:loginForm.password,token:''}))
           
               
    }
}
export const { userAdd } = userSlice.actions;
export default userSlice.reducer;